﻿using System;
using System.Collections.ObjectModel;

namespace AppGene.DataModel
{
    /// <summary>
    /// The class provides a description for logical foreign key.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class LogicalForeignKeyAttribute
        : Attribute
    {
        /// <summary>
        /// Creates a logical foreign key instance.
        /// </summary>
        /// <param name="column">The column of the foreign key.</param>
        /// <param name="parentClass">The type of parent class.</param>
        /// <param name="parentColumn">The parent column of the foreign key.</param>
        public LogicalForeignKeyAttribute(string column,
            Type parentClass,
            string parentColumn)
            : this(new string[] { column },
                parentClass,
                new string[] { parentColumn })
        { }

        /// <summary>
        /// Creates a logical foreign key instance.
        /// </summary>
        /// <param name="column">The column of the foreign key.</param>
        /// <param name="column2">The second column of the foreign key.</param>
        /// <param name="parentClass">The type of parent class.</param>
        /// <param name="parentColumn">The parent column of the foreign key.</param>
        /// <param name="parentColumn2">The second parent column of the foreign key.</param>
        public LogicalForeignKeyAttribute(string column,
            string column2,
            Type parentClass,
            string parentColumn,
            string parentColumn2)
            : this(new string[] { column, column2 },
                parentClass,
                new string[] { parentColumn, parentColumn2 })
        { }

        /// <summary>
        /// Creates a logical foreign key instance.
        /// </summary>
        /// <param name="columns">The column array of the foreign key.</param>
        /// <param name="parentClass">The type of parent class.</param>
        /// <param name="parentColumns">The parent column array of the foreign key.</param>
        public LogicalForeignKeyAttribute(string[] columns,
            Type parentClass,
            string[] parentColumns)
        {
            this.Columns = new ReadOnlyCollection<string>(columns);
            this.ParentClass = parentClass;
            this.ParentColumns = new ReadOnlyCollection<string>(parentColumns);
        }

        /// <summary>
        /// Gets the column collection for the foreign key.
        /// </summary>
        public ReadOnlyCollection<string> Columns { get; private set; }

        /// <summary>
        /// Gets the parent column collection for the foreign key.
        /// </summary>
        public ReadOnlyCollection<string> ParentColumns { get; private set; }

        /// <summary>
        /// Gets the type of parent class.
        /// </summary>
        public Type ParentClass { get; private set; }

        /// <summary>
        /// Gets the foreign key name.
        /// </summary>
        public string Name { get; set; }
    }
}
